package com.boang.web;

import jakarta.servlet.*;

import java.io.IOException;

/*
  @author: 13813
  @date: 2024/7/11 10:31
*/
public class ServletDemo01 implements Servlet {

    //调一次，初始化
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("init");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    //调多次，处理请求
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("service");
        //接收客户的请求数据
        String name = servletRequest.getParameter("name");
        System.out.println("name = " + name);
        //响应数据到客户端
        servletResponse.getWriter().write("hello world");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    //调一次，销毁对象
    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
